***************************************************************************************************************************************
***************************************************************************FIGURE S5.2*************************************************
***************************************************************************************************************************************
cd "E:\workdata\704429\Projektfiles\Co-residence"

use analysis_out_data_all_pairs, clear

**Generate stacked datasæt**
gen id=_n
replace koen1 = koen1 - 1 
replace koen2 = koen2 - 1 

save temp_analysis1.dta, replace
foreach var in stemt residentialstability stemte_2009 pnr FOED_DAG koen  {
	rename `var'1 `var'3
	rename `var'2 `var'1
	rename `var'3 `var'2
}

append using temp_analysis1.dta

lab def koen 0 "male" 1 "female"
lab val koen1 koen
lab val koen2 koen

gen estimate_13=.
gen lowerconf=.
gen upperconf=.
gen months=.

**1 month**
foreach num of numlist 1(2)73 { 
capture drop month13_factor 
gen month13_factor=month13 + 83.5 + 61 - `num' 

	quietly reg stemt1 b84.month13_factor   ///
	if month13_factor >= 72 & month13_factor <= 96	
	
	quietly replace estimate_13=_b[83.month13_factor] in `num'/`num'
	quietly replace lowerconf=_b[83.month13_factor]-1.96*_se[83.month13_factor] in `num'/`num'
	quietly replace upperconf=_b[83.month13_factor]+1.96*_se[83.month13_factor] in `num'/`num'
	quietly replace months=`num' in `num'/`num'
} 

gen temp = estimate_13 in 61/61
egen max = mean(temp) if estimate_13!=.
gen max_min = -max

set scheme s2mono
scatter estimate_13 months, ///
 yline(0) ///
 || rspike lowerconf upperconf months ///
 || line max months, lpattern(dash) ///
 || line max_min months, ///
 legend(off) ///
 lpattern(dash) ///
 ytitle("Estimate") ///
 ylabel(-0.15 (0.05) 0.15) ///
 xlabel(61 "0" 73 "12" 49 "-12" 37 "-24" 25 "-36" 13 "-48" 1 "-60") ///
 xtitle("Placebo cutoffs (0 = True cutoff)") ///
  graphregion(color(white)) ///
 saving(move_in_graphs/mock_cuts1.gph, replace) 

graph export  move_in_graphs/mock_cuts_vote1.png, width(800) height(600) replace

**2 months**
drop estimate_13 lowerconf upperconf months month13_factor max* temp

gen estimate_13=.
gen lowerconf=.
gen upperconf=.
gen months=.

foreach num of numlist 1(4)73 { 
capture drop month13_factor 
gen month13_factor=month13 + 83.5 + 61 - `num' 

	quietly reg stemt1 b85.month13_factor   ///
	if month13_factor >= 72 & month13_factor <= 96	
	
	quietly replace estimate_13=_b[82.month13_factor] in `num'/`num'
	quietly replace lowerconf=_b[82.month13_factor]-1.96*_se[82.month13_factor] in `num'/`num'
	quietly replace upperconf=_b[82.month13_factor]+1.96*_se[82.month13_factor] in `num'/`num'
	quietly replace months=`num' in `num'/`num'
} 
gen temp = estimate_13 in 61/61
egen max = mean(temp) if estimate_13!=.
gen max_min = -max

set scheme s2mono
scatter estimate_13 months, ///
 yline(0) ///
 || rspike lowerconf upperconf months ///
 || line max months, lpattern(dash) ///
 || line max_min months, ///
 legend(off) ///
 lpattern(dash) ///
 ytitle("Estimate") ///
 ylabel(-0.15 (0.05) 0.15) ///
 xlabel(61 "0" 73 "12" 49 "-12" 37 "-24" 25 "-36" 13 "-48" 1 "-60") ///
 xtitle("Placebo cutoffs (0 = True cutoff)") ///
 graphregion(color(white)) ///
 saving(move_in_graphs/mock_cuts2.gph, replace) 

graph combine move_in_graphs/mock_cuts1.gph move_in_graphs/mock_cuts2.gph, ///
 graphregion(color(white)) ///
 xsize(16) ysize(8) 
 


 
